import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.Timer;
import javax.swing.border.Border;

import com.speljohan.rsbot.accessors.Player;
import com.speljohan.rsbot.bot.Bot;
import com.speljohan.rsbot.event.events.ServerMessageEvent;
import com.speljohan.rsbot.event.listeners.PaintListener;
import com.speljohan.rsbot.script.Calculations;
import com.speljohan.rsbot.script.Constants;
import com.speljohan.rsbot.script.Methods;
import com.speljohan.rsbot.script.Script;
import com.speljohan.rsbot.script.wrappers.RSInterface;
import com.speljohan.rsbot.script.wrappers.RSItemTile;
import com.speljohan.rsbot.script.wrappers.RSNPC;
import com.speljohan.rsbot.script.wrappers.RSObject;
import com.speljohan.rsbot.script.wrappers.RSPlayer;
import com.speljohan.rsbot.script.wrappers.RSTile;
import com.speljohan.rsbot.util.ScreenshotUtil;

//Deviant Woodcutter by Deviant of the RSBot Forums
//Code formatting by MajorSanchez (Moderator Extraordinaire) and Eclipse.. one key rofl nub

public class DeviantWoodcutter extends Script implements PaintListener,
		ActionListener {
	// Yes, I know these should be tabbed once more over if I really
	// wanted to make the code truly formatted. So sue me.
	private enum Action {
		OPENDOOR, ANTIBAN, BANK, WALKTOTREES, WALKTOBANK, WAITING, CHOP, WAIT
	}

	public static double getOVersion() {
		return 2.95;
	}

	public int[] axeID = new int[] { 1351, 1349, 1353, 1361, 1355, 1357, 1359,
			6739, 13470 };
	private final int[] nestIds = { 5070, 5071, 5072, 5073, 5074, 5075, 5076,
			7413, 11966 };
	public int exp = 1;
	public int price;
	public int Nest = 0;
	public int[] treesID;
	public int chopped;
	public int responds;
	public String[] names;
	public String namet = "nobody";
	public int bankerID;
	public int lastExp;
	public int currenttab;
	public int randomInt;
	public long waiting1;
	public int lastTreeIndex;
	public int Door;
	public double x1;
	public double x2 = 1.5;
	public int y1;
	public int xx1;
	public int xx2;
	public int yy1;
	public int yy2;
	public Timer timer;
	public int GambleInt, GambleInt1, rambleInt;
	public int startingLevel = 0;
	public int startingExperience = 0;
	public int previousSpeed;
	public boolean booth = false;
	public boolean dMages = false;
	public boolean start;
	public boolean responder = true;
	public boolean wieldaxe;
	public boolean deposit = false;
	public boolean edge = false;
	public boolean chest = false;
	public boolean walkingLocation = false;
	public boolean GE = false;
	public boolean sMages = false;
	public boolean sYews = false;

	public boolean gnome = false;

	boolean outdated = false;
	Point mousePos;
	RSObject bankBooth;
	RSObject tree;
	RSNPC npc;
	RSTile[] bankToTrees;
	RSTile[] treesToBank;
	RSTile[] treeLocs;

	RSTile waitTile;
	RSTile bankTile;

	Color BG = new Color(0, 0, 0, 100);
	Color DarkGreen;
	public long startTime = System.currentTimeMillis();

	public long nextTalk = System.currentTimeMillis() + random(50000, 60000);
	public long scriptStartTime;
	public String message;
	private String currentState = "Starting up..";

	private String chopping = "Starting up..";;

	String[] list = { "[Draynor]Oaks", "[Draynor]Willows",
			"[Port Sarim]Willows", "[Seers]Maples", "[Barb]Willows",
			"[Grand Exchange]Yews", "[Catherby]Yews", "[Seers]Yews",
			"[Edgeville]Yews", "[Port Sarim]Yews", "[Rimmington]Yews",
			"[Seers]Magics", "[Duel Arena]Magics" };

	JFrame frame;

	JButton buttonStart = new JButton("Start");

	JButton buttonAccept = new JButton("Accept");

	JButton buttonCancel = new JButton("Cancel");

	JButton buttonOkay = new JButton("Okay");

	JLabel lblChop = new JLabel("Location:");

	JLabel lblStatus = new JLabel("Checking for update...");
	JLabel lblQuestion = new JLabel("Would you like to check for new version?");
	JLabel lblType = new JLabel("Can you wield an axe?");
	JLabel lblcur = new JLabel("Current:");
	JLabel lblold = new JLabel("Latest:");
	JLabel lblstat = new JLabel("Status:");
	JLabel lblwarning = new JLabel("Auto-Clicks Advertisements");
	JLabel statV = new JLabel("" + message);
	JLabel currentV = new JLabel("" + getVersion());
	public double currV = DeviantWoodcutter.getOVersion();
	JLabel oldV = new JLabel("" + currV);
	JLabel lblRespondw = new JLabel("Please fill in all");
	JLabel lblRespond1 = new JLabel("Name 1");
	JLabel lblRespond2 = new JLabel("Name 2");
	JLabel lblRespond3 = new JLabel("Name 3");
	JComboBox combo = new JComboBox(list);
	JRadioButton axe = new JRadioButton("Yes");
	JRadioButton noaxe = new JRadioButton("No");
	JPanel locationPanel = new JPanel(new BorderLayout());
	JPanel midButtonPanel = new JPanel(new BorderLayout());
	JPanel bottomButtonPanel = new JPanel(new BorderLayout());
	JPanel startButtonPanel = new JPanel(new BorderLayout());
	JPanel buttonPanel = new JPanel(new BorderLayout());
	JPanel versionPanel = new JPanel(new BorderLayout());
	JPanel responderPanel = new JPanel(new BorderLayout());
	// GridLayout GridLayout1 = new GridLayout(2, 2);
	// GridLayout GridLayout2 = new GridLayout(3, 3);
	// GridLayout GridLayout3 = new GridLayout(3, 2);
	// GridLayout GridLayout4 = new GridLayout(3, 3);
	GridLayout MainGridLayout = new GridLayout(0, 1);
	JCheckBox chk = new JCheckBox("Cannot wield axe");
	JCheckBox enableR = new JCheckBox("Enable Chat Responder");
	TextField name1, name2, name3;
	public boolean depositItem;
	public String[] chat = new String[100];
	public String[] chat2 = new String[100];
	public String oldChat = "";
	public String[] oldQ = { "" };
	public int level;

	public void actionPerformed(final ActionEvent e) {
		if (e.getActionCommand().contains("able")) {
			if (!enableR.isSelected()) {
				responderPanel.setVisible(false);
			}
			if (enableR.isSelected()) {
				responderPanel.setVisible(true);
			}
			frame.pack();
			return;
		}
		if (e.getActionCommand().contains("art")) {
			if (combo.getSelectedItem().toString().equals("[Draynor]Willows")) {
				price = 18;
				exp = 68;
				x1 = 1.2;
				x2 = 1.2;
				xx1 = -2;
				xx2 = 2;
				yy1 = -2;
				yy2 = 2;
				chopping = "Willows";
				bankTile = new RSTile(3091, 3245);
				bankToTrees = new RSTile[] { new RSTile(3092, 3245),
						new RSTile(3086, 3233) };
				treeLocs = new RSTile[] { new RSTile(3089, 3234),
						new RSTile(3086, 3236), new RSTile(3086, 3237),
						new RSTile(3084, 3238), new RSTile(3088, 3232),
						new RSTile(3089, 3227) };
				booth = true;
				bankerID = 2213;
				treesID = new int[] { 5553, 5551, 5552 };
				treesToBank = reversePath(bankToTrees);
			}

			if (combo.getSelectedItem().toString().equals(
					"[Grand Exchange]Yews")) {
				booth = false;
				price = 430;
				exp = 175;
				x1 = 1.5;
				xx1 = -2;
				xx2 = 2;
				yy1 = -3;
				yy2 = -2;
				GE = true;
				chopping = "Yews";
				bankToTrees = new RSTile[] { new RSTile(3168, 3488),
						new RSTile(3174, 3488), new RSTile(3180, 3488),
						new RSTile(3185, 3488), new RSTile(3191, 3488),
						new RSTile(3195, 3491), new RSTile(3196, 3495),
						new RSTile(3209, 3501) };
				treeLocs = new RSTile[] { new RSTile(3210, 3504),
						new RSTile(3205, 3504), new RSTile(3222, 3503) };
				bankerID = 6533;
				bankTile = new RSTile(3167, 3489);
				treesID = new int[] { 1309, 1212 };
				treesToBank = reversePath(bankToTrees);
			}

			if (combo.getSelectedItem().toString().equals("[Draynor]Oaks")) {
				booth = true;
				price = 25;
				exp = 37;
				x1 = 1.5;
				xx1 = -2;
				xx2 = 2;
				yy1 = -2;
				yy2 = 2;
				chopping = "Oaks";
				bankToTrees = new RSTile[] { new RSTile(3092, 3245),
						new RSTile(3100, 3245) };
				treeLocs = new RSTile[] { new RSTile(3102, 3242),
						new RSTile(3107, 3248) };
				bankerID = 2213;
				bankTile = new RSTile(3091, 3245);
				treesID = new int[] { 1281, 1212 };
				treesToBank = reversePath(bankToTrees);
			}

			if (combo.getSelectedItem().toString()
					.equals("[South Falador]Yews")) {
				booth = true;
				price = 430;
				exp = 175;
				x1 = 1.5;
				xx1 = -2;
				xx2 = 2;
				yy1 = -2;
				yy2 = 2;
				walkingLocation = true;
				chopping = "Yews";
				bankToTrees = new RSTile[] { new RSTile(3011, 3356),
						new RSTile(3007, 3346), new RSTile(3007, 3332),
						new RSTile(3007, 3318) };
				waitTile = new RSTile(3006, 3316);
				treeLocs = new RSTile[] { new RSTile(2997, 3312),
						new RSTile(3020, 3316) };
				bankerID = 11758;
				treesID = new int[] { 1309, 1212 };
				treesToBank = reversePath(bankToTrees);
			}

			if (combo.getSelectedItem().toString().equals("[Catherby]Yews")) {
				booth = true;
				price = 430;
				exp = 175;
				x1 = 1.5;
				xx1 = -2;
				xx2 = 2;
				yy1 = -2;
				yy2 = -2;
				chopping = "Yews";
				bankToTrees = new RSTile[] { new RSTile(2808, 3440),
						new RSTile(2805, 3433), new RSTile(2796, 3433),
						new RSTile(2783, 3432), new RSTile(2771, 3430),
						new RSTile(2763, 3429) };
				treeLocs = new RSTile[] { new RSTile(2758, 3434),
						new RSTile(2760, 3428), new RSTile(2761, 3432),
						new RSTile(2756, 3431), new RSTile(2755, 3434),
						new RSTile(2766, 3428) };
				bankerID = 2213;
				bankTile = new RSTile(2807, 3442);
				treesID = new int[] { 1309, 1212 };
				treesToBank = reversePath(bankToTrees);
			}

			if (combo.getSelectedItem().toString().equals("[Seers]Yews")) {
				booth = true;
				sYews = true;
				price = 430;
				exp = 175;
				x1 = 1.5;
				xx1 = -2;
				xx2 = 2;
				yy1 = -2;
				yy2 = 2;
				chopping = "Yews";
				bankTile = new RSTile(2727, 3494);
				bankToTrees = new RSTile[] { new RSTile(2724, 3492),
						new RSTile(2725, 3477), new RSTile(2721, 3467),
						new RSTile(2715, 3463) };
				treeLocs = new RSTile[] { new RSTile(2715, 3460),
						new RSTile(2706, 3460), new RSTile(2706, 3465) };
				bankerID = 25808;
				treesID = new int[] { 1309, 1212 };
				treesToBank = reversePath(bankToTrees);
			}

			if (combo.getSelectedItem().toString().equals("[Seers]Maples")) {
				booth = true;
				price = 35;
				exp = 100;
				x1 = 1.0;
				x2 = 1.5;
				xx1 = -2;
				xx2 = 2;
				yy1 = -2;
				yy2 = 2;
				chopping = "Maples";
				bankTile = new RSTile(2727, 3494);
				bankToTrees = new RSTile[] { new RSTile(2727, 3492),
						new RSTile(2729, 3500) };
				treeLocs = new RSTile[] { new RSTile(2727, 3502),
						new RSTile(2730, 3501), new RSTile(2733, 3500),
						new RSTile(2722, 3501) };
				bankerID = 25808;
				treesID = new int[] { 1307, 1308 };
				treesToBank = reversePath(bankToTrees);
			}

			if (combo.getSelectedItem().toString().equals("[Seers]Magics")) {
				booth = true;
				sMages = true;
				price = 1260;
				exp = 250;
				x1 = 1.25;
				x2 = 1.25;
				xx1 = -2;
				xx2 = 2;
				yy1 = -2;
				yy2 = 2;
				chopping = "Magics";
				bankTile = new RSTile(2727, 3494);
				bankToTrees = new RSTile[] { new RSTile(2726, 3492),
						new RSTile(2726, 3486), new RSTile(2727, 3482),
						new RSTile(2727, 3477), new RSTile(2723, 3472),
						new RSTile(2720, 3466), new RSTile(2720, 3461),
						new RSTile(2720, 3455), new RSTile(2714, 3451),
						new RSTile(2709, 3448), new RSTile(2709, 3441),
						new RSTile(2708, 3436), new RSTile(3706, 3430),
						new RSTile(2699, 3425) };
				treeLocs = new RSTile[] { new RSTile(2697, 3424),
						new RSTile(2692, 3425), new RSTile(2691, 3427),
						new RSTile(2694, 3425) };
				bankerID = 25808;
				treesID = new int[] { 1306, 1308 };
				treesToBank = reversePath(bankToTrees);
			}

			if (combo.getSelectedItem().toString().equals("[Edgeville]Yews")) {
				booth = true;
				price = 430;
				exp = 175;
				x1 = 1.5;
				xx1 = -1;
				xx2 = 3;
				edge = true;
				bankTile = new RSTile(3095, 3491);
				chopping = "Yews";
				bankToTrees = new RSTile[] { new RSTile(3093, 3491),
						new RSTile(3088, 3484), new RSTile(3090, 3470) };
				treeLocs = new RSTile[] { new RSTile(3086, 3469),
						new RSTile(3086, 3481) };
				bankerID = 26972;
				treesID = new int[] { 1309, 1212 };
				treesToBank = reversePath(bankToTrees);
			}
			if (combo.getSelectedItem().toString().equals("[Port Sarim]Yews")) {
				booth = true;
				price = 430;
				exp = 175;
				x1 = 1.5;
				xx1 = -2;
				xx2 = 2;
				yy1 = -2;
				yy2 = 2;
				chopping = "Yews";
				bankTile = new RSTile(3091, 3245);
				bankToTrees = new RSTile[] { new RSTile(3094, 3244),
						new RSTile(3085, 3248), new RSTile(3078, 3258),
						new RSTile(3074, 3269), new RSTile(3066, 3276),
						new RSTile(3058, 3275) };
				treeLocs = new RSTile[] { new RSTile(3054, 3272) };
				bankerID = 25808;
				treesID = new int[] { 1309, 1212 };
				treesToBank = reversePath(bankToTrees);
			}
			if (combo.getSelectedItem().toString()
					.equals("[Port Sarim]Willows")) {
				price = 18;
				exp = 68;
				x1 = 1.2;
				x2 = 1.2;
				xx1 = -2;
				xx2 = 2;
				yy1 = -2;
				yy2 = 2;
				chopping = "Willows";
				bankTile = new RSTile(3091, 3245);
				bankToTrees = new RSTile[] { new RSTile(3092, 3245),
						new RSTile(3081, 3248), new RSTile(3067, 3254),
						new RSTile(3060, 3254) };
				treeLocs = new RSTile[] { new RSTile(3057, 3255),
						new RSTile(3060, 3255), new RSTile(3059, 3253),
						new RSTile(3058, 3251) };
				booth = true;
				bankerID = 2213;
				treesID = new int[] { 5553, 5551, 5552 };
				treesToBank = reversePath(bankToTrees);
			}
			if (combo.getSelectedItem().toString().equals("[Rimmington]Yews")) {
				booth = true;
				price = 430;
				exp = 175;
				x1 = 1.5;
				xx1 = -2;
				xx2 = 2;
				yy1 = -2;
				yy2 = 2;
				chopping = "Yews";
				bankTile = new RSTile(3011, 3354);
				bankToTrees = new RSTile[] { new RSTile(3012, 3355),
						new RSTile(3012, 3358), new RSTile(3006, 3357),
						new RSTile(3006, 3353), new RSTile(3007, 3348),
						new RSTile(3006, 3342), new RSTile(3006, 3334),
						new RSTile(3006, 3329), new RSTile(3007, 3323),
						new RSTile(3004, 3316), new RSTile(2999, 3313),
						new RSTile(2989, 3308), new RSTile(2985, 3306),
						new RSTile(2978, 3294), new RSTile(2971, 3293),
						new RSTile(2963, 3289), new RSTile(2961, 3284),
						new RSTile(2960, 3277), new RSTile(2960, 3271),
						new RSTile(2961, 3264), new RSTile(2961, 3258),
						new RSTile(2960, 3249), new RSTile(2953, 3242),
						new RSTile(2947, 3238), new RSTile(2943, 3234) };
				treeLocs = new RSTile[] { new RSTile(2936, 3230),
						new RSTile(2935, 3226), new RSTile(2934, 3234),
						new RSTile(2940, 3233) };
				bankerID = 11758;
				treesID = new int[] { 1309 };
				treesToBank = reversePath(bankToTrees);
			}
			if (combo.getSelectedItem().toString().equals("[Barb]Willows")) {
				price = 18;
				exp = 68;
				x1 = 1.2;
				x2 = 1.2;
				xx1 = -3;
				xx2 = -1;
				yy1 = -2;
				yy2 = 2;
				Door = 20195;
				deposit = true;
				chopping = "Willows";
				bankTile = new RSTile(2537, 3573);
				bankToTrees = new RSTile[] { new RSTile(2535, 3574),
						new RSTile(2534, 3574), new RSTile(2532, 3571),
						new RSTile(2520, 3571), new RSTile(2519, 3574),
						new RSTile(2519, 3567), new RSTile(2517, 3563),
						new RSTile(2515, 3559), new RSTile(2519, 3576) };
				treeLocs = new RSTile[] { new RSTile(2517, 3567),
						new RSTile(2513, 3561), new RSTile(2513, 3558),
						new RSTile(2510, 3555), new RSTile(2519, 3578),
						new RSTile(2522, 3582), new RSTile(2517, 3580),
						new RSTile(2517, 3581) };
				bankerID = 20228;
				booth = false;
				treesID = new int[] { 5553, 5551, 5552 };
				treesToBank = reversePath(bankToTrees);

			}
			if (combo.getSelectedItem().toString().equals("[Gnome]Yews")) {
				booth = true;
				gnome = true;
				price = 430;
				exp = 175;
				x1 = 1.5;
				xx1 = -2;
				xx2 = 2;
				yy1 = -2;
				yy2 = 2;
				chopping = "Yews";
				bankTile = new RSTile(2447, 3427);
				bankToTrees = new RSTile[] { new RSTile(2431, 3416),
						new RSTile(2433, 2422), new RSTile(2437, 2472),
						new RSTile(2440, 3430), new RSTile(2443, 3435) };
				treeLocs = new RSTile[] { new RSTile(2439, 3436),
						new RSTile(2433, 3441), new RSTile(2433, 3426) };
				bankerID = 25808;
				treesID = new int[] { 1309, 1212 };
				treesToBank = reversePath(bankToTrees);
			}
			if (combo.getSelectedItem().toString().equals("[Duel Arena]Magics")) {
				booth = false;
				chest = true;
				Door = 27854;
				dMages = true;
				price = 1260;
				exp = 250;
				x1 = 1.25;
				x2 = 1.25;
				xx1 = -2;
				xx2 = 2;
				yy1 = -2;
				yy2 = 2;
				chopping = "Magics";
				bankTile = new RSTile(3381, 3269);
				bankToTrees = new RSTile[] { new RSTile(3383, 3268),
						new RSTile(3376, 3266), new RSTile(3368, 3265),
						new RSTile(3359, 3265), new RSTile(3353, 3266),
						new RSTile(3350, 3272), new RSTile(3349, 3278),
						new RSTile(3353, 3284), new RSTile(3361, 3286),
						new RSTile(3363, 3292), new RSTile(3368, 3297),
						new RSTile(3367, 3309) };
				treeLocs = new RSTile[] { new RSTile(3369, 3312),
						new RSTile(3356, 3311) };
				bankerID = 25808;
				treesID = new int[] { 1306, 1308 };
				treesToBank = reversePath(bankToTrees);
			}
			if (chk.isSelected()) {
				wieldaxe = false;
			} else {
				wieldaxe = true;
			}

			if (enableR.isSelected()) {
				responder = true;
				names = new String[] { "" + name1.getText(),
						"" + name2.getText(), "" + name3.getText() };
			} else {
				responder = false;
			}
			if (isLoggedIn()) {
				System.out.println("Deviant Woodcutter Initialized...");
				frame.dispose();
				start = true;
				frame.setVisible(false);
			}
		}
	}

	void antiBan() {
		GambleInt = random(1, 30);
		final int treeIndex = closestTree(treeLocs);
		if (!bank.getInterface().isValid()
				&& !RSInterface.getInterface(Constants.INTERFACE_DEPOSITBOX)
						.isValid() && currentState != "Banking..."
				&& !getMyPlayer().isMoving()
				&& (treeIndex != -1 || currentState == "Waiting...")) {
			if (GambleInt == 1) {
				turnCamera();
				wait(random(300, 500));
			}
			if (GambleInt == 2) {
				final int xA = random(0, 750);
				final int yA = random(0, 500);
				mousePos = getMouseLocation();
				moveMouse(xA, yA);
				wait(random(300, 500));
				moveMouse(mousePos, 7, 7);
				wait(random(100, 200));
				turnCamera();
				wait(random(300, 500));
			}
			if (GambleInt == 3) {
				if (getCurrentTab() != Constants.TAB_INVENTORY) {
					currenttab = getCurrentTab();
					openTab(Constants.TAB_INVENTORY);
					wait(random(300, 500));
					turnCamera();
					wait(random(300, 500));
				}
			}
			if (GambleInt == 5) {
				turnCamera();
				wait(random(300, 500));
				final int xA = random(0, 750);
				final int yA = random(0, 500);
				mousePos = getMouseLocation();
				moveMouse(xA, yA);
				wait(random(300, 500));
				moveMouse(mousePos, 7, 7);
				wait(random(100, 200));
			}
			if (GambleInt == 6) {
				turnCamera();
				wait(random(300, 500));
			}

			if (GambleInt == 7) {
				mousePos = getMouseLocation();
				currenttab = getCurrentTab();
				openTab(1);
				wait(random(300, 500));
				openTab(currenttab);
				wait(random(300, 500));
				moveMouse(mousePos, 7, 7);
				wait(random(100, 200));
			}
			if (GambleInt == 8) {
				mousePos = getMouseLocation();
				moveMouse(random(0, 450), random(0, 450));
				wait(random(300, 500));
				moveMouse(mousePos, 7, 7);
				wait(random(100, 200));
			}
			if (GambleInt == 9) {
				turnCamera();
				wait(random(300, 500));
			}
			if (GambleInt == 10) {
				final int xA = random(0, 750);
				final int yA = random(0, 500);
				mousePos = getMouseLocation();
				moveMouse(xA, yA);
				wait(random(300, 500));
				moveMouse(mousePos, 7, 7);
				wait(random(100, 200));
				turnCamera();
				wait(random(300, 500));
			}
			if (GambleInt == 11) {
				turnCamera();
				wait(random(300, 500));
				final int xA = random(0, 750);
				final int yA = random(0, 500);
				mousePos = getMouseLocation();
				moveMouse(xA, yA);
				wait(random(300, 500));
				moveMouse(mousePos, 7, 7);
				wait(random(100, 200));
			}
		}
	}

	public boolean atBank(final RSTile tile, final String action) {
		try {
			final Point location = Calculations.tileToScreen(tile);
			if (location.x == -1 || location.y == -1) {
				return false;
			}
			moveMouse(location, 3, 3);
			clickMouse(false);
			return atMenu(action);
			// if
			// (getMenuItems().get(0).toLowerCase().contains(action.toLowerCase()))
			// {
			// clickMouse(true);
			// } else {
			// clickMouse(false);
			// if (!atMenu(action)) return false;
			// }
			// wait(random(500, 1000));
			// while (true) {
			// if (!getMyPlayer().isMoving()) break;
			// wait(random(500, 1000));
			// }
			// return true;
		} catch (final Exception e) {
			return false;
		}
	}

	public boolean atGate(final RSTile tile, final String action) {
		try {

			final Point location = Calculations.tileToScreen(tile.getX(), tile
					.getY(), 0.5, 1, 0);

			if (location.x == -1 || location.y == -1) {
				return false;
			}
			moveMouse(location, 3, 3);
			clickMouse(true);

		} catch (final Exception e) {
			return false;
		}
		return false;
	}

	public boolean atTree(final RSTile tile, final String action) {
		try {
			if (tileOnScreen(tree.getLocation())) {
				final Point location = Calculations.tileToScreen(tile.getX(),
						tile.getY(), x1, x2, 0);

				if (location.x == -1 || location.y == -1) {
					return false;
				}
				moveMouse(location, 3, 3);
				clickMouse(true);
			}
		} catch (final Exception e) {
			return false;
		}
		return false;
	}

	// Keeps finding midtile until the tile is onMap //Fusion89k <3
	private RSTile checkTile(final RSTile tile) {
		if (tileOnMap(tile)) {
			return tile;
		}
		final RSTile loc = getMyPlayer().getLocation();
		final RSTile walk = new RSTile((loc.getX() + tile.getX()) / 2, (loc
				.getY() + tile.getY()) / 2);
		return tileOnMap(walk) ? walk : checkTile(walk);
	}

	public int closestTree(final RSTile[] tiles) {
		int closest = -1;
		for (int i = 0; i < tiles.length; i++) {
			final RSTile tile = tiles[i];
			if (getObjectAt(tile) != null) {
				if (closest == -1 && isTree(getObjectAt(tile).getID())) {
					closest = i;
					continue;
				}
				if (closest == -1) {
					continue;
				}
				if (isTree(getObjectAt(tile).getID())
						&& distanceTo(getObjectAt(tile)) < distanceTo(getObjectAt(tiles[closest]))) {
					closest = i;
				}
			}
		}
		return closest;
	}

	// Creating the GUI
	public boolean createGUI() {

		// if (!isLoggedIn()) {
		// log("You Must Be Logged In To Run This Script!!!<<");
		// stopAllScripts();
		// }
		// if (isLoggedIn()) {
		frame = new JFrame("Deviant Woodcutter");
		// frame.setLayout(null);
		// frame.setResizable(false);
		// frame.setSize(320, 500);
		frame.setLocationRelativeTo(null);
		combo.setForeground(Color.red);
		combo.setBackground(Color.black);
		frame.setBackground(Color.black);
		buttonStart.setBackground(Color.black);
		buttonStart.setForeground(Color.red);
		// buttonStart.setBounds(65, 124, 100, 25);
		// combo.setBounds(20, 51, 150, 18);
		// axe.setBounds(20, 85, 150, 18);
		// noaxe.setBounds(20, 100, 150, 18);
		// lblChop.setBounds(20, 30, 100, 20);
		// lblType.setBounds(20, 70, 150, 18);

		buttonPanel.add(versionPanel, BorderLayout.NORTH);
		buttonPanel.add(midButtonPanel, BorderLayout.CENTER);
		midButtonPanel.add(locationPanel, BorderLayout.NORTH);
		midButtonPanel.add(bottomButtonPanel, BorderLayout.CENTER);
		midButtonPanel.add(responderPanel, BorderLayout.SOUTH);
		buttonPanel.add(startButtonPanel, BorderLayout.SOUTH);

		frame.add(buttonPanel);
		// buttonPanel.setSize(300, 450);
		final Border black = BorderFactory.createLineBorder(Color.black);
		buttonPanel.setBorder(BorderFactory.createTitledBorder(black,
				"Deviant Script Options"));
		versionPanel.setBorder(BorderFactory.createTitledBorder(black,
				"Version"));
		responderPanel.setBorder(BorderFactory.createTitledBorder(black,
				"Chat Responder"));

		// locationPanel.setLayout(GridLayout1);
		locationPanel.add(combo);
		// locationPanel.add(new JLabel(""));
		// locationPanel.add(new JLabel(""));
		// locationPanel.add(new JLabel(""));
		locationPanel.setBorder(BorderFactory.createTitledBorder(black,
				"Location Selection"));
		// bottomButtonPanel.setLayout(MainGridLayout);
		bottomButtonPanel.add(chk, BorderLayout.NORTH);
		bottomButtonPanel.add(enableR, BorderLayout.SOUTH);

		bottomButtonPanel.setBorder(BorderFactory.createTitledBorder(black,
				"Options"));

		// versionPanel.setLayout(GridLayout4);
		final String color = currV > getVersion() ? "red" : "green";
		lblcur.setText("<html><body>" + lblcur.getText() + "<font color="
				+ color + "><br>" + currentV.getText()
				+ "</font></body></html>");
		lblold.setText("<html><body><P ALIGN=\"right\">" + lblold.getText()
				+ "<font color=" + color + "><br>" + oldV.getText()
				+ "</font></P></body></html>");
		lblstat.setText("<html><body>" + lblstat.getText() + "<font color="
				+ color + "><br>" + statV.getText() + "</font></body></html>");
		versionPanel.add(lblcur, BorderLayout.WEST);
		versionPanel.add(lblold, BorderLayout.CENTER);
		versionPanel.add(lblstat, BorderLayout.EAST);
		// versionPanel.add(currentV);
		// versionPanel.add(oldV);
		// versionPanel.add(statV);
		// versionPanel.add(new JLabel(""));
		// versionPanel.add(new JLabel(""));

		final JPanel one = new JPanel(new BorderLayout());
		final JPanel two = new JPanel(new BorderLayout());
		final JPanel three = new JPanel(new BorderLayout());

		name2.setText("Please change");
		name2.setForeground(Color.red);
		name3.setText("Please change");
		name3.setForeground(Color.red);

		one.add(lblRespond1, BorderLayout.WEST);
		one.add(name1, BorderLayout.EAST);
		two.add(lblRespond2, BorderLayout.WEST);
		two.add(name2, BorderLayout.EAST);
		three.add(lblRespond3, BorderLayout.WEST);
		three.add(name3, BorderLayout.EAST);

		// responderPanel.setLayout(GridLayout3);
		responderPanel.add(one, BorderLayout.NORTH);
		responderPanel.add(two, BorderLayout.CENTER);
		responderPanel.add(three, BorderLayout.SOUTH);
		enableR.setSelected(true);
		enableR.addActionListener(this);

		// startButtonPanel.setLayout(Gin my ridLayout2);
		// startButtonPanel.add(new JLabel(""));
		// startButtonPanel.add(new JLabel(""));
		// startButtonPanel.add(new JLabel(""));
		// startButtonPanel.add(new JLabel(""));
		// startButtonPanel.add(new JLabel(""));
		// startButtonPanel.add(new JLabel(""));
		// startButtonPanel.add(new JLabel(""));
		// startButtonPanel.add(new JLabel(""));
		startButtonPanel.add(buttonStart, BorderLayout.NORTH);

		buttonStart.addActionListener(this);
		frame.setVisible(true);
		frame.pack();
		while (!start) {
			wait(100);
		}
		// }
		return true;
	}

	public void depositAllBut(final int... items) {
		int inventory[] = getInventoryArray();
		if (inventory == null || items == null) {
			return;
		}
		for (int index = 0; index < inventory.length; ++index) {
			inventory = getInventoryArray();
			if (inventory == null || items == null) {
				return;
			}
			if (getInventoryCount() < 2) {
				return;
			}
			depositItem = true;
			if (inventory[index] == -1) {
				depositItem = false;
			}
			for (int item = 0; item < items.length; ++item) {
				if (inventory[index] == items[item]) {
					depositItem = false;
				}
			}
			if (depositItem) {
				clickMouse(getDepositInventoryItemPoint(index), false);
				atMenu("Deposit-All");
				wait(random(500, 650));
			}
		}
	}

	private RSTile findBusyTree() {
		int closestTo1 = 0;
		int closestTo2 = 0;
		int closestTo3 = 0;

		try {
			final int[] validPlayers = Bot.getClient().getPlayerIndexArray();
			final Player[] players = Bot.getClient().getPlayerArray();

			for (final int x : validPlayers) {
				final RSPlayer player = new RSPlayer(players[x]);

				try {
					if (Methods.distanceBetween(player.getLocation(),
							treeLocs[0]) <= 4) {
						closestTo1++;
					}
					if (Methods.distanceBetween(player.getLocation(),
							treeLocs[1]) <= 4) {
						closestTo2++;
					}
					if (sMages || sYews || GE) {
						if (Methods.distanceBetween(player.getLocation(),
								treeLocs[2]) <= 4) {
							closestTo3++;
						}
					}
				} catch (final Exception e) {
				}
			}
		} catch (final Exception e) {
		}

		if (closestTo1 > closestTo2 && closestTo1 > closestTo3) {
			return treeLocs[0];
		}
		if (closestTo2 > closestTo1 && closestTo2 > closestTo3) {
			return treeLocs[1];
		}
		if (closestTo3 > closestTo2 && closestTo3 > closestTo1) {
			return treeLocs[2];
		} else {
			return treeLocs[0];
		}
	}

	private Action getAction() {
		final int treeIndex = closestTree(treeLocs);

		if (treeIndex == -1 && !isInventoryFull()
				&& distanceTo(treeLocs[0]) < 20) {
			return Action.WAITING;
		}
		if (findObject(Door) != null
				&& distanceTo(findObject(Door).getLocation()) < 14
				&& currentState != "Chopping..." && (deposit || chest)) {
			return Action.OPENDOOR;
		}
		if (isInventoryFull() && tileOnScreen(bankTile)) {
			return Action.BANK;
		}
		if (!isInventoryFull() && distanceTo(treeLocs[0]) > 16) {
			return Action.WALKTOTREES;
		}
		if (isInventoryFull() && distanceTo(bankTile) > 5) {
			return Action.WALKTOBANK;
		}
		if (!isInventoryFull() && getMyPlayer().getAnimation() != -1) {
			return Action.ANTIBAN;
		}
		if (treeIndex != -1 && distanceTo(treeLocs[treeIndex]) < 16) {
			return Action.CHOP;
		}

		return Action.WAIT;
	}

	public String getAuthor() {
		return "Deviant";
	}

	public String[] getChatMessages(final boolean stripName) {
		final String[] temp = new String[100];
		int tempi = 0;
		for (int i = 155; i >= 56; i--) {
			if (getChildText(137, i).contains("<col=0000ff>")) {
				if (stripName) {
					temp[tempi] = getChildText(137, i).substring(
							getChildText(137, i).indexOf("<col=0000ff>") + 12);
					tempi++;
				} else {
					temp[tempi] = getChildText(137, i).replaceAll(
							"<col=0000ff>", "");
					tempi++;
				}
			}
		}
		return temp;
	}

	public String getChildText(final int iface, final int child) {
		return RSInterface.getInterface(iface).getChild(child).getText();
	}

	public RSObject getClosestTreeByID(final int... ids) {
		RSObject cur = null;
		double dist = -1;

		for (int x = 0; x < 104; x++) {
			for (int y = 0; y < 104; y++) {
				final RSObject o = getObjectAt(x + Bot.getClient().getBaseX(),
						y + Bot.getClient().getBaseY());

				if (o != null) {
					boolean isObject = false;
					for (final int id : ids) {
						if (o.getID() == id) {
							isObject = true;
							break;
						}
					}
					if (isObject) {
						final double distTmp = calculateDistance(getMyPlayer()
								.getLocation(), o.getLocation());

						if (cur == null) {
							dist = distTmp;
							cur = o;
						} else if (distTmp < dist) {
							cur = o;
							dist = distTmp;
						}
					}
				}
			}
		}
		return cur;
	}

	public Point getDepositInventoryItemPoint(final int invIndex) {
		final int col = invIndex % 7;
		final int row = invIndex / 7;
		final int x = 121 + col * 48;
		final int y = 85 + row * 50;
		return new Point(x, y);
	}

	public String getName() {
		return "Deviant Woodcutter";
	}

	@Override
	public String getScriptCategory() {
		return "Woodcutting";
	}

	@Override
	public String getScriptDescription() {
		String html = "";
		html += "<html>";
		html += "<head>";
		html += "</head>";
		html += "<body>";
		html += "<br><b>Deviant Woodcutter</b></br>";
		html += "<br>A frame will pop up asking you a location when you run the script!</br>";
		html += "</body>";
		return html;
	}

	// Author stuff
	public double getVersion() {
		return 2.95;
	}

	private boolean isMoving() { // Fusion89k <3
		if (!getMyPlayer().isMoving()) {
			return false;
		}
		if (getDestination() != null) {
			if (distanceTo(getDestination()) < 6) {
				return false;
			} else {
				return true;
			}
		}
		return false;
	}

	public boolean isTree(final int treeID) {
		for (final int id : treesID) {
			if (id == treeID) {
				return true;
			}
		}
		return false;
	}

	@Override
	public int loop() {
		try {
			int treeIndex = closestTree(treeLocs);

			tree = getClosestTreeByID(treesID);
			setMaxAltitude();
			nest();
			if (responder) {
				talk();
			}
			final Action action = getAction();
			if (getEnergy() > random(60, 100)) {
				setRun(true);
			}

			if (action != null) {
				switch (action) {

				case CHOP:
					treeIndex = closestTree(treeLocs);

					if (distanceTo(treeLocs[treeIndex]) < 7
							&& distanceTo(treeLocs[treeIndex]) > 3
							&& getMyPlayer().getAnimation() == -1) {
						turnToTile(treeLocs[treeIndex]);
					}

					if (treeIndex != -1 && !isInventoryFull()) {

						if (distanceTo(treeLocs[treeIndex]) < 5) {
							if (getMyPlayer().getAnimation() != -1
									&& lastTreeIndex == treeIndex) {
								return random(200, 300);
							}
							lastTreeIndex = treeIndex;

							if (tileOnScreen(treeLocs[treeIndex])
									&& !getMyPlayer().isMoving()
									&& getMyPlayer().getAnimation() == -1) {
								atTree(tree.getLocation(), "Chop down");
								currentState = "Chopping...";
								return random(500, 1000);
							}
						}

						if (treeIndex == 1 && edge) {
							yy1 = -2;
							yy2 = -2;
						}
						if (treeIndex == 0 && edge) {
							yy1 = 2;
							yy2 = 2;
						}

						if (distanceTo(treeLocs[treeIndex]) > 4
								&& !getMyPlayer().isMoving()) {
							currentState = "Walking to new " + chopping;
							walkTileMM(checkTile(new RSTile(treeLocs[treeIndex]
									.getX()
									+ random(xx1, xx2), treeLocs[treeIndex]
									.getY()
									+ random(yy1, yy2))));
						}

					}

					break;

				case WALKTOBANK:
					if (isInventoryFull() && distanceTo(bankTile) > 5
							&& !isMoving()) {
						currentState = "Walking to bank...";
						walkToBank();
					}

				case WALKTOTREES:
					if (!isInventoryFull() && distanceTo(treeLocs[0]) > 16
							&& !isMoving()) {
						currentState = "Walking to trees...";
						walkToTrees();
					}
					break;
				case BANK:
					if (isInventoryFull() && tileOnScreen(bankTile)
							&& !getMyPlayer().isMoving()) {

						if (booth && !bank.getInterface().isValid()) {
							currentState = "Banking...";
							turnToTile(bankTile);
							atBank(bankTile, "use-quickly");
							return random(500, 800);
						}
						if (chest && !bank.getInterface().isValid()) {
							currentState = "Banking...";
							turnToTile(bankTile);
							atBank(bankTile, "");
							return random(500, 800);
						}
						if (GE && !bank.getInterface().isValid()) {
							currentState = "Banking...";
							setCameraRotation(90 + random(-5, 5));
							npc = getNearestNPCByID(bankerID);
							atNPC(npc, "Bank Banker");
							return random(500, 800);
						}

						if (deposit
								&& !RSInterface.getInterface(
										Constants.INTERFACE_DEPOSITBOX)
										.isValid()) {
							currentState = "Banking...";
							atTile(bankTile, "");
							return random(1000, 2000);
						}

						if (RSInterface.getInterface(
								Constants.INTERFACE_DEPOSITBOX).isValid()) {
							if (wieldaxe) {
								currentState = "Depositing...";
								clickMouse(random(332, 349), random(268, 283),
										true);
								return random(500, 700);
							} else {
								depositAllBut(axeID);
								return random(1000, 2000);
							}
						}

						if (bank.getInterface().isValid()) {
							if (wieldaxe) {
								clickMouse(random(384, 408), random(299, 313),
										true);
							} else {
								bank.depositAllExcept(axeID);
							}
							bank.close();
							return random(500, 700);
						}
					}
					break;
				case ANTIBAN:
					if (getMyPlayer().getAnimation() != -1) {
						antiBan();
					}
					break;
				case OPENDOOR:

					if (findObject(Door) != null
							&& currentState != "Chopping..."
							&& currentState != "Walking to new " + chopping) {
						currentState = "Opening door...";
						if (chest) {
							openDoor2();
						}
						if (deposit) {
							openDoor();
						}
					}
					break;
				case WAITING:
					treeIndex = closestTree(treeLocs);
					if (treeIndex == -1 && !isInventoryFull()
							&& !getMyPlayer().isMoving()) {
						currentState = "Waiting...";
						antiBan();
						final RSTile busyTile = findBusyTree();
						if (sMages || sYews || GE || dMages) {
							if (distanceTo(busyTile) > 4) {
								walkTileMM(new RSTile(busyTile.getX()
										+ random(-2, 2), busyTile.getY()
										+ random(-2, 2)));
								return random(700, 1000);
							}
						}

						if (edge && distanceTo(busyTile) > 4) {
							if (busyTile == treeLocs[0]) {
								yy1 = 2;
								yy2 = 3;
							}
							if (busyTile == treeLocs[1]) {
								yy1 = -2;
								yy2 = -3;
							}

							walkTileMM(new RSTile(busyTile.getX()
									+ random(xx1, xx2), busyTile.getY()
									+ random(yy1, yy2)));
							return random(700, 1000);
						}
					}
					break;
				case WAIT:
					break;
				}
			}

		}

		catch (final Exception e) {
		}
		return random(200, 300);
	}

	public void nest() {
		final RSItemTile nest = getGroundItemByID(nestIds);
		if (nest != null) {
			log("Found a nest...");
			turnToTile(nest);
			atTile(nest, "Take");
			currentState = "Picking up nest...";
			Nest++;
		}
	}

	public void onFinish() {
		log("Chopped " + chopped + " " + chopping);
		ScreenshotUtil.takeScreenshot(true);
		Bot.getEventManager().removeListener(PaintListener.class, this);
	}

	public void onRepaint(final Graphics g) {
		if (isLoggedIn() && (!frame.isValid() || frame.isVisible())) {
			long millis = System.currentTimeMillis() - startTime;

			if (lastExp == 0) {
				lastExp = skills.getCurrentSkillExp(Constants.STAT_WOODCUTTING);
			}

			if (skills.getCurrentSkillExp(Constants.STAT_WOODCUTTING) > lastExp) {
				lastExp = skills.getCurrentSkillExp(Constants.STAT_WOODCUTTING);
				chopped++;
			}

			if (startingLevel == 0 || startingExperience == 0) {
				startingLevel = skills
						.getCurrentSkillLevel(Constants.STAT_WOODCUTTING);
				startingExperience = skills
						.getCurrentSkillExp(Constants.STAT_WOODCUTTING);
			}
			final long hours = millis / (1000 * 60 * 60);
			millis -= hours * 1000 * 60 * 60;
			final long minutes = millis / (1000 * 60);
			millis -= minutes * 1000 * 60;
			long timeToTalk = (nextTalk - System.currentTimeMillis()) / 1000;
			if (timeToTalk < 0) {
				timeToTalk = 0;
			}

			final long seconds = millis / 1000;
			final int topX = 515 - 205, topY = 325 - 90, x = topX + 5;
			int y = topY + 5;
			final int topX2 = 515 - 205, topY2 = 100 - 70;
			final int x22 = topX2 + 5;
			int y22 = topY2 + 5;

			if (responder) {
				g.setColor(BG);
				g.fill3DRect(topX2, topY2, 516 - topX2, 100 - topY2, true);
				g.setColor(Color.red);
				g.setFont(new Font("Verdana", Font.BOLD, 12));
				g.drawString("Deviant Chat Responder", x22, y22 += 13);
				g.drawString("Last responded to: " + namet, x22, y22 += 13);
				g
						.drawString("Responded " + responds + " times", x22,
								y22 += 13);
				g.drawString("Wait time: " + timeToTalk, x22, y22 += 13);
			}

			g.setColor(BG);
			g.fill3DRect(topX, topY, 516 - topX, 340 - topY, true);
			g.setColor(Color.red);
			g.setFont(new Font("Verdana", Font.BOLD, 12));
			g.drawString(getName(), x, y += 13);
			g.drawString("Runtime: " + hours + "h " + minutes + "min "
					+ seconds + "sec.", x, y += 13);
			g.drawString(chopping + " chopped: " + chopped, x, y += 13);
			g.drawString("Money gained: " + chopped * price, x, y += 13);
			g
					.drawString(
							"Gained "
									+ (skills
											.getCurrentSkillLevel(Constants.STAT_WOODCUTTING) - startingLevel)
									+ " levels", x, y += 13);
			g.drawString(skills.getXPToNextLevel(Constants.STAT_WOODCUTTING)
					/ exp + " " + chopping + " till next level", x, y += 13);
			g.setColor(Color.white);
			g.drawString("State: " + currentState, x, y += 13);
		}
	}

	public boolean onStart(final String[] args) {
		start = false;
		if (isLoggedIn()) {
			scriptStartTime = System.currentTimeMillis();
			name1 = new TextField(getMyPlayer().getName());
			name2 = new TextField(name1.getColumns());
			name3 = name2;
			createGUI();
			return true;
		}
		log.warning("Please log in first.");
		return false;
	}

	public void openDoor() {
		if (!getMyPlayer().isMoving()) {
			if (distanceTo(findObject(Door)) > 2) {
				if (getMyPlayer().getLocation().getX() >= 2522) {
					walkTileMM(new RSTile(2523, 3571));
				}
				if (getMyPlayer().getLocation().getX() <= 2521) {
					walkTileMM(new RSTile(2521, 3571));
				}
				wait(random(1000, 2000));
			}
			if (!getMyPlayer().isMoving()) {
				setCameraRotation(270 + random(-5, 5));
				atDoor(findObject(Door), "e", "Open");
				wait(random(1500, 2000));
			}
		}
	}

	public void openDoor2() {
		if (!getMyPlayer().isMoving()) {
			if (distanceTo(findObject(27854)) > 2) {
				walkTileMM(new RSTile(3349, 3279));
				wait(random(1000, 2000));
			}
			if (!getMyPlayer().isMoving()) {
				setCameraRotation(360 + random(-5, 5));
				atGate(findObject(27854).getLocation(), "Open");
				wait(random(1500, 2000));
			}
		}
	}

	// If you're still reading this code, you have no life <3

	// Chat Responder

	public boolean replyToPlayer(String text) {
		GambleInt1 = random(1, 2);
		for (final String name : names) {
			text = text.toLowerCase();
			if (!text.contains("" + name)
					&& (text.contains("wc") || text.contains("woodcut") || text
							.contains("woodcutting"))
					&& text.contains("?")
					&& (text.contains("lvls") || text.contains("levels") || text
							.contains("is your level in"))) {
				if (GambleInt1 == 1) {
					level = skills
							.getCurrentSkillLevel(Constants.STAT_WOODCUTTING);
					final String[] replyArray = { "" + level, "" + level + "." };
					final String reply = replyArray[random(0, replyArray.length)];
					sendText(reply, true);
					log("===================================");
					log("Replied with: " + reply);
				}

				if (GambleInt1 == 2) {
					final char[] key = new char[] { KeyEvent.VK_ENTER,
							KeyEvent.VK_X, KeyEvent.VK_2 };
					Bot.getInputManager().pressKey(key[0]);
					try {
						Thread.sleep(random(300, 600));
					} catch (final Exception e) {
					}
					Bot.getInputManager().releaseKey(key[0]);
					try {
						Thread.sleep(random(300, 600));
					} catch (final Exception e) {
					}
					sendText("x", false);
					sendText("2", false);
					level = skills
							.getCurrentSkillLevel(Constants.STAT_WOODCUTTING);
					log("===================================");
					log("Replied with: My Woodcutting Level is" + level);
				}
				nextTalk = System.currentTimeMillis() + random(50000, 60000);
				return true;
			}

			if (text.contains("" + name)
					&& (text.contains("lvl") || text.contains("level")
							|| text.contains("wc?") || text.contains("lv") || text
							.contains("lv"))) {

				if (GambleInt1 == 1) {
					level = skills
							.getCurrentSkillLevel(Constants.STAT_WOODCUTTING);
					final String[] replyArray = { "" + level, "" + level + "." };
					final String reply = replyArray[random(0, replyArray.length)];
					sendText(reply, true);
					log("===================================");
					log("Replied with: " + reply);
				}
				if (GambleInt1 == 2) {
					final char[] key = new char[] { KeyEvent.VK_ENTER,
							KeyEvent.VK_X, KeyEvent.VK_2 };
					Bot.getInputManager().pressKey(key[0]);
					try {
						Thread.sleep(random(300, 600));
					} catch (final Exception e) {
					}
					Bot.getInputManager().releaseKey(key[0]);
					try {
						Thread.sleep(random(300, 600));
					} catch (final Exception e) {
					}
					sendText("x", false);
					sendText("2", false);
					level = skills
							.getCurrentSkillLevel(Constants.STAT_WOODCUTTING);
					log("===================================");
					log("Replied with: My Woodcutting Level is" + level);
				}
				nextTalk = System.currentTimeMillis() + random(50000, 60000);
				return true;
			}
			if (text.startsWith("hi") && text.endsWith("hi")
					|| text.contains("hello") || text.startsWith("hey")
					&& text.endsWith("hey") || text.startsWith("sup")
					&& text.endsWith("sup")) {
				level = skills.getCurrentSkillLevel(Constants.STAT_WOODCUTTING);
				final String[] replyArray = { "hey", "hi", "yo", "hello" };
				final String reply = replyArray[random(0, replyArray.length)];
				sendText(reply, true);
				log("===================================");
				log("Replied with: " + reply);
				nextTalk = System.currentTimeMillis() + random(30000, 40000);
				return true;
			}

			if (text.contains("botter") || text.contains("macro")
					|| text.contains("bot") || text.contains("auto")
					|| text.contains("botting")) {
				level = skills.getCurrentSkillLevel(Constants.STAT_WOODCUTTING);
				final String[] replyArray = { "lol", "noob", "rofl", "lmao" };
				final String reply = replyArray[random(0, replyArray.length)];
				sendText(reply, true);
				log("===================================");
				log("Replied with: " + reply);
				nextTalk = System.currentTimeMillis() + random(30000, 40000);
				return true;
			}
			if (text.startsWith("" + name)
					&& (text.endsWith("" + name) || text.endsWith("?"))) {
				level = skills.getCurrentSkillLevel(Constants.STAT_WOODCUTTING);
				final String[] replyArray = { "?", "what?", "???", "yes?" };
				final String reply = replyArray[random(0, replyArray.length)];
				sendText(reply, true);
				log("===================================");
				log("Replied with: " + reply);
				nextTalk = System.currentTimeMillis() + random(30000, 40000);
				return true;
			}

		}
		return false;
	}

	public void serverMessageRecieved(final ServerMessageEvent sme) {
	}

	// Camera Configuration \\
	public void setMaxAltitude() {
		Bot.getInputManager().pressKey((char) 38);
		wait(random(500, 1000));
		Bot.getInputManager().releaseKey((char) 38);
	}

	public void talk() {
		chat = getChatMessages(true);
		chat2 = getChatMessages(false);
		if (chat[0] == null || oldChat.equalsIgnoreCase(chat2[0])) {
			return;
		}
		if (oldQ[0].equalsIgnoreCase(chat2[0])) {
			return;
		}
		final String temp = chat2[0];
		final String name = temp.substring(0, temp.indexOf(":"));

		if (name.equalsIgnoreCase(getMyPlayer().getName())) {
			return;
		}
		final long timerTalk = nextTalk - System.currentTimeMillis();
		if (timerTalk > 0) {
			oldQ[0] = chat2[0];
			return;
		}
		if (replyToPlayer(chat[0])) {
			namet = temp.substring(0, temp.indexOf(":"));

			log("Replied to: " + chat2[0]);
			log("===================================");
			responds++;
			oldQ[0] = chat2[0];
		}
	}

	public void turnCamera() {
		final char[] LR = new char[] { KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT };
		final char[] UD = new char[] { KeyEvent.VK_DOWN, KeyEvent.VK_UP };
		final char[] LRUD = new char[] { KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT,
				KeyEvent.VK_UP, KeyEvent.VK_UP };
		final int random2 = random(0, 2);
		final int random1 = random(0, 2);
		final int random4 = random(0, 4);

		if (random(0, 3) == 0 && getMyPlayer().getAnimation() != -1) {
			Bot.getInputManager().pressKey(LR[random1]);
			try {
				Thread.sleep(random(100, 400));
			} catch (final Exception e) {
			}

			Bot.getInputManager().pressKey(UD[random2]);
			try {
				Thread.sleep(random(300, 600));
			} catch (final Exception e) {
			}

			Bot.getInputManager().releaseKey(UD[random2]);
			try {
				Thread.sleep(random(100, 400));
			} catch (final Exception e) {
			}

			Bot.getInputManager().releaseKey(LR[random1]);
		} else {
			Bot.getInputManager().pressKey(LRUD[random4]);
			if (random4 > 1) {
				try {
					Thread.sleep(random(300, 600));
				} catch (final Exception e) {
				}
			} else {
				try {
					Thread.sleep(random(500, 900));
				} catch (final Exception e) {
				}
			}
			Bot.getInputManager().releaseKey(LRUD[random4]);
		}
	}

	private boolean walkPath(final RSTile rst[]) {
		for (int i = rst.length - 1; i >= 0; i--) {
			if (walkPath(rst[i])) {
				return true;
			}
		}
		return false;
	}

	private boolean walkPath(final RSTile rst) {
		if (distanceTo(rst) < 16) {
			walkTileMM(checkTile(randomizeTile(rst, 2, 2)));
			return true;
		} else {
			return false;
		}
	}

	public boolean walkToBank() {
		return walkPath(treesToBank);
	}

	public boolean walkToTrees() {
		return walkPath(bankToTrees);
	}
}